package com.it.myd.help;

import com.it.myd.bean.box.world.Material;
import com.it.myd.bean.box.world.Resource;
import com.it.myd.bean.main.User;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ResourceLoader {
    public static String Tree_MaxHp = ResourceProp.getString("tree_maxhp");
    public static String Tree_Hp = ResourceProp.getString("tree_hp");
    public static String Tree_Res = ResourceProp.getString("tree_rec");
    public static String Rock_MaxHp = ResourceProp.getString("rock_maxhp");
    public static String Rock_Hp = ResourceProp.getString("rock_hp");
    public static String Rock_Res = ResourceProp.getString("rock_rec");

    public Resource GatRes_Tree(){
        Resource res = new Resource() {
            @Override
            public List<Material> getMaterial(String o_output,String n_output) {
                List<Material> list = new ArrayList<>();
                int sh = Integer.parseInt(n_output) - Integer.parseInt(o_output);
                MaterialLoader materialLoader = new MaterialLoader();
                Material woods = materialLoader.getWoods(sh*2,getUseUser());
                list.add(woods);
                return list;
            }

            @Override
            public List<Material> dead() {
                return null;
            }
        };

        SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMddHHmmss");
        String createtime = sdf.format(System.currentTimeMillis());
        Random random = new Random();
        int randomNumber = random.nextInt(999) + 1;
        String formattedNumber = String.format("%03d", randomNumber);
        res.setRes_Name("Tree_"+createtime+formattedNumber);

        User user = new User();
        user.setUser_name("admin");
        user.setUser_id(10000);
        res.setCreatUser(user);

        res.setRes_MaxHp(Tree_MaxHp);
        res.setRes_Hp(Tree_Hp);
        res.setRes_Rec(Tree_Res);
        res.setCreattime(createtime);
        res.setRes_Type("tree");
        res.setRes_State("1");
        res.setRes_Output("0");

        return res;
    }

    public Resource GatRes_Rock(){
        Resource res = new Resource() {
            @Override
            public List<Material> getMaterial(String o_output,String n_output) {
                List<Material> list = new ArrayList<>();
                int sh = Integer.parseInt(n_output) - Integer.parseInt(o_output);
                MaterialLoader materialLoader = new MaterialLoader();
                Material stones = materialLoader.getStones(sh,getUseUser());
                list.add(stones);
                return list;
            }

            @Override
            public List<Material> dead() {
                return null;
            }
        };

        SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMddHHmmss");
        String createtime = sdf.format(System.currentTimeMillis());
        Random random = new Random();
        int randomNumber = random.nextInt(999) + 1;
        String formattedNumber = String.format("%03d", randomNumber);
        res.setRes_Name("Rock_"+createtime+formattedNumber);

        User user = new User();
        user.setUser_name("admin");
        user.setUser_id(10000);
        res.setCreatUser(user);

        res.setRes_MaxHp(Rock_MaxHp);
        res.setRes_Hp(Rock_Hp);
        res.setRes_Rec(Rock_Res);
        res.setCreattime(createtime);
        res.setRes_Type("rock");
        res.setRes_State("1");
        res.setRes_Output("0");

        return res;
    }



}
